
*Code for AKM: MA/AKM/AKM_merger_cvrnr.do

*Table 1

use "I:\Workdata\702525\Alex\persondata_v2.dta", clear

drop if cvrnr==.
drop if lonind==.
drop if lonind<=1
gen byte female=(koen==2)
gen married=(civst==11)
gen max_educ=int(hffsp/1000000)
gen educ_basic=(max_educ<=25)
gen educ_voc= (max_educ==35)
gen educ_college= (max_educ>=40&max_educ<.)
destring ansaar, replace
gen tenure=year-ansaar
replace tenure=. if tenure>exper
bysort pnr lbnr: egen temp_firstyear=min(year)
by pnr: egen temp_firstyearever=min(year)
replace tenure=year-temp_firstyear if tenure==.&temp_firstyear!=temp_firstyearever
merge m:1 year using "D:\Workdata\702525\users\Daniel\DecentralizationSorting\Alex\deflator", nogen keep(1 3)
replace lonind=lonind*100/deflator
replace timelon=timelon*100/deflator
merge 1:1 pnr year using "$home\archive\samlesamle1", keepus(lonsystem) keep(1 3) nogen
bysort cvrnr: egen standardrate=sum((lonsystem==4))
bysort cvrnr: egen totalbargain=sum((lonsystem!=.))
ren arledgr frac_unemployed
ren tlonkval quality_hour
ren aldernov age
gen educ=1 if max_educ<=25
replace educ=2 if max_educ==35
replace educ=3 if max_educ>=40&max_educ<=50
replace educ=4 if max_educ>=60&max_educ<.
drop if educ==.
drop if frac_unemployed>500
drop if exper==.
replace timelon=lonind/1800 if timelon==0
gen loghrwage=log(timelon)
gen logincome=log(lonind)
bysort cvrnr year: gen emp=_N
bysort cvrnr year: egen meanlogincome=mean(logincome)
bysort cvrnr year: egen meanlogwage=mean(loghrwage)
by cvrnr year: gen count=_n
bysort cvrnr: egen maxemp=max(emp)
drop if maxemp<=5

*non-connected firms
ren pnr pnr0
merge m:1 cvrnr year using "$project\manager\manager_all_cvrnr2", keep(1 3) keepus(pnr) nogen
ren pnr pnrm
ren pnr0 pnr

merge 1:1 pnr year using "$project\akm_1step", keep(1 3) nogen

sum age female married educ* exper tenure logincome loghrwage
sum age exper tenure logincome loghrwage emp,d
sum age female married educ* exper tenure logincome loghrwage if _merge==3
sum age exper tenure logincome loghrwage emp if _merge==3,d

merge m:1 cvrnr year using "$home\firmdata_v1", keep(1 3) keepus(vapp) nogen
merge m:1 cvrnr year using "$project\temp_ind_region", keep(1 3) nogen

sum emp meanlogincome meanlogwage vapp est_age if count==1,d
sum emp meanlogincome meanlogwage vapp est_age if count==1& _merge==3,d






